package com.neusoft.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.neusoft.demo.po.Goods;
import com.neusoft.demo.po.Goods_type;
import com.neusoft.demo.service.GoodsService;
import com.neusoft.demo.service.Goods_typeService;

@Controller
public class GoodsController {
	
	@Autowired
	GoodsService goodsservice;
	@Autowired
	Goods_typeService goods_typeService;

	@RequestMapping("/shangpinguanli")
	public ModelAndView queryGoods(ModelAndView mv) {
		List<Goods> queryGoods = goodsservice.queryGoods();
		mv.addObject("queryGoods",queryGoods);
		mv.setViewName("shangpinguanli");
		return mv;
	}
	
//	修改的链接
	@RequestMapping("shangpinguanlixiugai")
	public ModelAndView shangpinguanlixiugai(Integer id,ModelAndView mv) {
		Goods queryGoodsById = goodsservice.queryGoodsById(id);
		List<Goods_type> queryGoods_type = goods_typeService.queryGoods_type();
		mv.addObject("queryGoods_type",queryGoods_type);
		mv.addObject("queryGoodsById",queryGoodsById);
		mv.setViewName("shangpinguanlixiugai");
		return mv;
	}
	
//	修改的页面
	@RequestMapping("/shangpinguanlixiugaitijiao")
	public ModelAndView updateGoods(Goods goods,ModelAndView mv) {
		System.out.println(goods);
		goodsservice.updateGoods(goods);
		List<Goods> queryGoods = goodsservice.queryGoods();
		mv.addObject("queryGoods",queryGoods);
		mv.setViewName("shangpinguanli");
		return mv;
	}
	
	@RequestMapping("/shangpinguanlishanchu")
	public ModelAndView shangpinguanlishanchu(Integer id,ModelAndView mv) {
		goodsservice.deleteGoods(id);
		List<Goods> queryGoods = goodsservice.queryGoods();
		mv.addObject("queryGoods",queryGoods);
		mv.setViewName("shangpinguanli");
		return mv;
	}
	
//	插入按钮
	@RequestMapping("/shangpinguanlicharu")
	public ModelAndView shangpinguanlicharu(Goods goods,ModelAndView mv) {
		System.out.println(goods);
//		goodsservice.addGoods(goods);
//		List<goods> queryGoods = goodsservice.queryGoods();
		List<Goods_type> queryGoods_type = goods_typeService.queryGoods_type();
		mv.addObject("queryGoods_type",queryGoods_type);
		mv.setViewName("shangpinguanlicharu");
		return mv;
	}
	
//	插入执行
	@RequestMapping("/shangpinguanlicharuzhixing")
	public ModelAndView shangpinguanlicharuzhixing(Goods goods,ModelAndView mv) {
		System.out.println(goods);
		goodsservice.addGoods(goods);
		List<Goods> queryGoods = goodsservice.queryGoods();
//		List<Goods_type> queryGoods_type = goods_typeService.queryGoods_type();
		mv.addObject("queryGoods",queryGoods);
		mv.setViewName("shangpinguanli");
		return mv;
	}
	
	@RequestMapping("/shangpinguanlichaxun")
	public ModelAndView shangpinguanlichaxun(Goods goods,ModelAndView mv) {
		System.out.println(goods);
		List<Goods> queryGoods = goodsservice.queryGoodsByLike(goods);
		mv.addObject("queryGoods",queryGoods);
		mv.setViewName("shangpinguanli");
		return mv;
	}
}
